package vo

import (
	"dc-news-admin-api/common/global/consts"
	"dc-news-admin-api/common/utils"
	"dc-news-admin-api/entity"
)

type LoginReq struct {
	User     string `json:"user"`
	Password string `json:"password"`
}

type CreateAdminReq struct {
	User string `json:"user"`
	Role string `json:"role"`
}

type ModifyAdminAuthReq struct {
	Role string `json:"role"`
}

type LoginResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Id          int    `json:"id"`
		User        string `json:"user"`
		Role        string `json:"role"`
		AccessToken string `json:"access_token"`
	} `json:"data"`
}

type PasswordResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Password string `json:"password"`
	} `json:"data"`
}

type GetAdminListResp struct {
	Code       int    `json:"code"`
	Msg        string `json:"msg"`
	Pagination struct {
		Page  int `json:"page"`
		Limit int `json:"limit"`
		Total int `json:"total"`
	} `json:"pagination"`
	Data []struct {
		Id   int    `json:"id"`
		User string `json:"user"`
		Role string `json:"role"`
	} `json:"data"`
}

func NewLoginResp(user *entity.Admin, token string) *LoginResp {
	return &LoginResp{
		Code: consts.OKCode,
		Msg:  "ok",
		Data: struct {
			Id          int    `json:"id"`
			User        string `json:"user"`
			Role        string `json:"role"`
			AccessToken string `json:"access_token"`
		}{
			Id:          user.ID,
			User:        user.Username,
			Role:        user.Role,
			AccessToken: token,
		},
	}
}

func NewPasswordResp(password string) *PasswordResp {
	return &PasswordResp{
		Code: consts.OKCode,
		Msg:  "ok",
		Data: struct {
			Password string `json:"password"`
		}{
			Password: password,
		},
	}
}

func NewGetAdminListResp(admins []entity.Admin, p *utils.Pagination) *GetAdminListResp {
	resp := &GetAdminListResp{
		Code: consts.OKCode,
		Msg:  "ok",
		Pagination: struct {
			Page  int `json:"page"`
			Limit int `json:"limit"`
			Total int `json:"total"`
		}{
			Page:  p.Page,
			Limit: p.Size,
			Total: p.Total,
		},
		Data: nil,
	}
	for _, admin := range admins {
		resp.Data = append(resp.Data,
			struct {
				Id   int    `json:"id"`
				User string `json:"user"`
				Role string `json:"role"`
			}{
				Id:   admin.ID,
				User: admin.Username,
				Role: admin.Role,
			})
	}
	return resp
}
